//获取传过来的id
var id = location.search.split('?id=')[1];
// console.log(id);

$.ajax({
    // 'url': '../电影json/movies.json',
    "url": "https://www.fastmock.site/mock/bb4157f45a0b5ffdcb3f6d984517a6c0/woniuMovie/getAllMovies",
    "success": function (data) {
        $.ajax({
            // 'url': '../电影json/types.json',
            'url': 'https://www.fastmock.site/mock/bb4157f45a0b5ffdcb3f6d984517a6c0/woniuMovie/getAllTypes',
            "success": function (name) {
                var arr = data.movies;
                var arr2 = name.types;
                // console.log(arr);
                console.log(arr2);
                // 筛选出id相符合的对象
                var arrObj = arr.filter(e => e.id == id)[0];
                console.log(arrObj);

                // 处理电影类型
                var movieType = arrObj.movieType;
                console.log(movieType);
                var newType = [];
                movieType.forEach(v => {
                    var arr3 = arr2.filter(e => e.id == v);
                    newType = newType.concat(arr3);
                });

                //这个就是当前需要的类型数组
                console.log(newType);


                //处理数据到页面
                additem(arrObj, newType);

                var clickTime1 = false;
                //选演出时间
                $('.button-box').on('click', 'button', function () {
                    $(this).css('border', '1px solid blue');
                    $(this).siblings().css('border', '');
                    arrObj.clickTime = $(this).text();
                    clickTime1 = true;
                })


                //点击购买按钮
                $('#chooseBtn').click(function () {
                    // console.log(arrObj);
                    if (clickTime1) {
                        //储存对应信息到本地
                        addData('payDetail', arrObj);
                        localStorage.removeItem("seat-mobile");
                        location.href = '../html/sit.html'
                    }
                    else {
                        alert('请选时间');
                    }

                })



            }
        })

    }
});
//返回上级菜单
$('#back').click(function () {
    window.history.go(-1);
})

$('.content-nav li').click(function () {
    $(this).toggleClass('active');
    $(this).siblings().removeClass('active');
})

function additem(e, type) {
    //e是对象
    //添加照片
    $('.left img').attr('src', `${e.imgSrc}`);
    $('.top').css('background', `url(${e.imgSrc}) no-repeat 0 -1.1rem`);
    $('.top').css('background-size', `cover`);

    //添加标题
    $('.right h4').text(e.title);

    //添加种类
    var typeStr = '';
    type.forEach(v => {
        typeStr += v.name + ','
    });
    typeStr = typeStr.substr(0, typeStr.length - 1);
    // console.log(typeStr);
    $(`.type`).text(typeStr);

    //添加持续时间
    $(`.duration`).text(e.duration);

    //添加评分
    $(`.score`).text(e.score);

    //简介
    $('.detail-infor').text(e.desc);

    //价格
    $('.movie-price').text(e.price);

    //语言
    $('.movie-language').text(e.language);

}

//获取本地数据
function getData(name) {
    var local = localStorage.getItem(name);
    if (local != null) {
        return JSON.parse(local);
    } else {
        return [];
    }
}
//添加本地信息
function addData(name, data) {
    localStorage.setItem(name, JSON.stringify(data));
}




